Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block hash system contract #229

Merged
merged 10 commits into from
Mar 13, 2024
Merged

Add block hash system contract #229

merged 10 commits into from
Mar 13, 2024

Conversation

okkothejawa
Copy link
Contributor

@okkothejawa okkothejawa commented Mar 11, 2024

Description

Adds L1BlockHashList which is just a mapping with a privileged setter in the form of block number: block hash and block hash: merkle root to store Bitcoin block hashes and merkle roots. It also adds Ownable.sol in lib so that this contract and future system contracts can have access control logic. It also installs foundry to the created systems_contracts folder so that we can test the contract logic.

Linked Issues

Testing

Wrote unit tests for each function. Here's the coverage:

| File                    | % Lines       | % Statements  | % Branches    | % Funcs       |
|-------------------------|---------------|---------------|---------------|---------------|
| src/L1BlockHashList.sol | 100.00% (6/6) | 100.00% (6/6) | 100.00% (0/0) | 100.00% (4/4) |
| test/Ownable.t.sol      | 100.00% (0/0) | 100.00% (0/0) | 100.00% (0/0) | 100.00% (1/1) |
| Total                   | 100.00% (6/6) | 100.00% (6/6) | 100.00% (0/0) | 100.00% (5/5) |

Here's the gas report:

| src/L1BlockHashList.sol:L1BlockHashList contract |                 |       |        |       |         |
|--------------------------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost                                  | Deployment Size |       |        |       |         |
| 374465                                           | 1434            |       |        |       |         |
| Function Name                                    | min             | avg   | median | max   | # calls |
| getBlockHash                                     | 493             | 493   | 493    | 493   | 102     |
| getMerkleRootFromBlockHash                       | 449             | 449   | 449    | 449   | 102     |
| getMerkleRootFromBlockNumber                     | 643             | 643   | 643    | 643   | 102     |
| setBlockInfo                                     | 24607           | 75498 | 75667  | 92767 | 102     |


| test/Ownable.t.sol:OwnableHarness contract |                 |       |        |       |         |
|--------------------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost                            | Deployment Size |       |        |       |         |
| 262209                                     | 914             |       |        |       |         |
| Function Name                              | min             | avg   | median | max   | # calls |
| acceptOwnership                            | 28012           | 28012 | 28012  | 28012 | 1       |
| owner                                      | 369             | 369   | 369    | 369   | 2       |
| pendingOwner                               | 391             | 391   | 391    | 391   | 1       |
| privilegedFunction                         | 23326           | 23393 | 23393  | 23460 | 2       |
| renounceOwnership                          | 22915           | 22915 | 22915  | 22915 | 1       |
| transferOwnership                          | 47328           | 47328 | 47328  | 47328 | 2       |

Docs

@eyusufatik eyusufatik merged commit b21a9e3 into nightly Mar 13, 2024
4 checks passed
@eyusufatik eyusufatik deleted the okko/blockhash-contract branch March 13, 2024 13:30
@otaliptus otaliptus mentioned this pull request Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EVM: impl. Blockhash system contracts
2 participants